package com.ccx.coachsite.ui.customview;

import com.ccx.coachsite.R;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class PageBarView extends LinearLayout implements IPageBar {

	private int count;

	public PageBarView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public PageBarView(Context context) {
		super(context);
	}

	public void setCount(int count) {
		this.count = count;
		buildView();
		if (count > 0)
			updateSelected(0);
	}

	private void buildView() {
		this.removeAllViews();

		for (int i = 0; i < this.count; i++) {
			ImageView imageView = new ImageView(getContext());
			imageView.setImageResource(R.drawable.gally_guide_normal);
			this.addView(imageView);
		}
	}

	@Override
	public void scrollHighLight(int scrollX) {

	}

	@Override
	public void updateSelected(int page) {
		for (int i = 0; i < this.getChildCount(); i++) {
			ImageView imageView = (ImageView) getChildAt(i);
			if (i == page)
				imageView.setImageResource(R.drawable.gally_guide_focused);
			else
				imageView.setImageResource(R.drawable.gally_guide_normal);
		}
	}
}
